import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @Description TODO
 * @Author zouxiang
 * @Date 2020/3/31/22:12
 */
public class TestStr {
    public static void main(String[] args) throws UnknownHostException {
        String str = "";
        long num = Runtime.getRuntime().freeMemory();
        long l = System.currentTimeMillis();
        for (int i = 0 ;i<5000;i++){
            str+=i;
        }
        System.out.println("str 占用内存："+(Runtime.getRuntime().freeMemory()-num));
        System.out.println("str 耗时："+(System.currentTimeMillis()-l));

        StringBuilder stringBuilder = new StringBuilder(5000);
        long num2 = Runtime.getRuntime().freeMemory();
        long l2 = System.currentTimeMillis();
        for (int i = 0 ;i<5000;i++){
            stringBuilder.append(i);
        }
        System.out.println("stringBuilder 占用内存："+(Runtime.getRuntime().freeMemory()-num2));
        System.out.println("stringBuilder 耗时："+(System.currentTimeMillis()-l2));


        StringBuffer stringBuffer = new StringBuffer(5000);
        long num3 = Runtime.getRuntime().freeMemory();
        long l3 = System.currentTimeMillis();
        for (int i = 0 ;i<5000;i++){
            stringBuffer.append(i);
        }
        System.out.println("stringBuffer 占用内存："+(Runtime.getRuntime().freeMemory()-num3));
        System.out.println("stringBuffer 耗时："+(System.currentTimeMillis()-l3));
        System.out.println(InetAddress.getLocalHost().getHostAddress());


    }
}

